<SCRIPT LANGUAGE = "JavaScript">

// Get the window object where the context menu was opened.
var oWindow = window.external.menuArguments;

var oUrl = oWindow.document.URL
var oTitle = oWindow.document.title

// Get the document object exposed through oWindow.
var oDocument = oWindow.document;

// Get the selection from oDocument.
// in oDocument.
var oSelect = oDocument.selection;

// Create a TextRange from oSelect.
var oSelectRange = oSelect.createRange();

// Get the text of the selection.
var sNewText = oSelectRange.text;

// Get the Regkey stored in registry using ActiveXObject
var WshShell = new ActiveXObject("WScript.Shell");
var dir = WshShell.RegRead("HKCU\\Software\\CaptureLink\\")


function saveXML() //Creates XML File
{
		var TristateFalse = 0;
		var ForWriting = 2;	
		myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
		
     		
		myActiveXObject.CreateTextFile(dir+"Link.xml");
		file = myActiveXObject.GetFile(dir+"Link.xml");
		
//		myActiveXObject.CreateTextFile(dir+Link.xml);
//		file = myActiveXObject.GetFile(dir+Link.xml);
		
		text = file.OpenAsTextStream(ForWriting, TristateFalse);
		var stringText="<?xml version='1.0' encoding='utf-8'?> ";		
		stringText+="\n<Root>\n<Title>"+oTitle+"</Title>";
		stringText+="\n<URL>"+oUrl+"</URL>";
		stringText+="\n<Description>"+sNewText+"</Description>\n</Root>";		text.Write(stringText);
		text.Close();
}


// Call saveXML() function.
if (sNewText.length != 0){
   saveXML();
}

//var WshShell = new ActiveXObject("WScript.Shell");
//var dir = WshShell.RegRead("HKCU\\Software\\CaptureLink\\")
//alert(dir);
//dir = "C:\\Program Files\\CaptureLinkInstaller\\CaptureLinkInstaller\\CaptureLinks.exe";

WshShell.Exec(dir+"CaptureLinks.exe");

</SCRIPT>

